package com.example.hp.yuejian5.model;

import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.MasterBean;
import com.example.hp.yuejian5.service.MasterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.hp.yuejian5.other.url.MASTERURL;

public class MasterModel {
    private Retrofit retrofit;
    private MasterService masterService;

    public MasterModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(MASTERURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        masterService=retrofit.create(MasterService.class);
    }
    public void masterList(final RetrofitListener listener)
    {
        Call<List<MasterBean>> call=masterService.masterlist();
        call.enqueue(new Callback<List<MasterBean>>() {
            @Override
            public void onResponse(Call<List<MasterBean>> call, Response<List<MasterBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<MasterBean>> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
